<template>
  <div class="xiecheng">
    <div class="admin_main_block">
      <div class="admin_main_block_top">
        <div class="admin_main_block_left">
          <div>
            <el-button
              v-if="isAuth('module:advertising:position:form')"
              type="success"
              icon="Plus"
              @click="router.push({ name: 'module_advertising_position_form' })">
              {{ i18n('common.create') }}
            </el-button>
          </div>
        </div>
        <div class="admin_main_block_right">
          <div>
            <el-button
              v-if="isAuth('module:advertising:position:delete')"
              type="danger"
              icon="Delete"
              @click="deleteHandle()">
              {{ i18n('common.batch_delete') }}
            </el-button>
          </div>
        </div>
      </div>

      <div class="admin_table_main">
        <el-table :data="dataList" v-loading="dataListLoading" @selection-change="selectionChangeHandle">
          <el-table-column type="selection" header-align="center" align="center">
          </el-table-column>

          <el-table-column prop="id" label="#" width="70px">
          </el-table-column>

          <el-table-column prop="title" :label="i18n('advertising.position.title')">
          </el-table-column>

          <el-table-column prop="width" :label="i18n('advertising.position.width')" width="100">
            <template v-slot="scope"> {{ scope.row.width }} px </template>
          </el-table-column>

          <el-table-column prop="height" :label="i18n('advertising.position.height')" width="100">
            <template v-slot="scope"> {{ scope.row.height }} px </template>
          </el-table-column>

          <el-table-column prop="is_open" :label="i18n('advertising.position.is_open')" width="100">
            <template v-slot="scope">
              {{ scope.row.is_open.text }}
            </template>
          </el-table-column>

          <el-table-column prop="create_time" :label="i18n('common.create_time')" width="160">
          </el-table-column>

          <el-table-column :label="i18n('common.handle')" fixed="right" width="450">
            <template v-slot="scope">
              <el-button
                v-if="isAuth('module:advertising:position:form')"
                type="primary"
                icon="Edit"
                @click="router.push({ name: 'module_advertising_position_form', query: { id: scope.row.id } })">
                {{ i18n('common.update') }}
              </el-button>

              <el-button
                v-if="isAuth('module:advertising:list')"
                type="info"
                icon="Search"
                @click="router.push({ name: 'module_advertising_list', query: { location_id: scope.row.id } })">
                {{ i18n('advertising.view') }}
              </el-button>

              <el-button
                v-if="isAuth('module:advertising:form') && scope.row.is_open.value == 1"
                type="success"
                icon="Plus"
                @click="router.push({ name: 'module_advertising_form', query: { location_id: scope.row.id } })">
                {{ i18n('advertising.create') }}
              </el-button>

              <el-button
                v-if="isAuth('module:advertising:position:delete')"
                type="danger"
                icon="Delete"
                @click="deleteHandle(scope.row.id)">
                {{ i18n('common.delete') }}
              </el-button>
            </template>
          </el-table-column>
        </el-table>

        <div class="admin_table_main_pagination">
          <el-pagination
            @size-change="sizeChangeHandle"
            @current-change="currentChangeHandle"
            :page-size="pageSize"
            :total="totalPage"
            :current-page="pageIndex"
            background
            layout="prev, pager, next,jumper,total">
          </el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup name="advertising-position-list">
  import { useBase } from "@/hooks/base/useBase"
  import { useTable } from "@/hooks/table/useTable"

  const { router, i18n, isAuth } = useBase()

  const model = ref('advertising/position')
  const dataForm = reactive([
    'title',
  ])

  const {
    dataList,
    pageIndex,
    pageSize,
    totalPage,
    dataListLoading,
    sizeChangeHandle,
    currentChangeHandle,
    selectionChangeHandle,
    getDataList,
    deleteHandle,
  } = useTable(model.value, dataForm)

  onMounted(() => {
    getDataList(model)
  })
</script>
